{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>yr</th>\n",
       "      <th>holiday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   yr  holiday  workingday  weathersit      temp       hum  windspeed   cnt\n",
       "0   0        0           0           2  0.344167  0.805833   0.160446   985\n",
       "1   0        0           0           2  0.363478  0.696087   0.248539   801\n",
       "2   0        0           1           1  0.196364  0.437273   0.248309  1349\n",
       "3   0        0           1           1  0.200000  0.590435   0.160296  1562\n",
       "4   0        0           1           1  0.226957  0.436957   0.186900  1600"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#导入必要的工具包\n",
    "import numpy as np #linear algebra\n",
    "import pandas as pd #data processing,CSV file I/O\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "dpath = './data/'\n",
    "data = pd.read_csv(dpath + 'day.csv')\n",
    "\n",
    "#删除一些不必要的特征\n",
    "del data['instant']\n",
    "del data['season']\n",
    "del data['mnth']\n",
    "del data['dteday']\n",
    "del data['casual']\n",
    "del data['registered']\n",
    "\n",
    "#atemp 和 temp两个特征从主观上可以判断是相似特征，可以只要其中一个，这里我只取 temp\n",
    "del data['atemp']\n",
    "\n",
    "#workingday 和 weekday 是相似特征，这里只取其中一个,workingday\n",
    "del data['weekday']\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "#seg_data = x.groupby(['yr'])\n",
    "#X_train, X_test, y_train, y_test\n",
    "#for name, group in seg_data:  \n",
    "#        print(name)  \n",
    "#        print(group)\n",
    "#X_seg_data = dict(list(x.groupby(['yr'])))\n",
    "#X_train = pd.DataFrame(X_seg_data[0])\n",
    "#X_test = pd.DataFrame(X_seg_data[1])\n",
    "\n",
    "#Y_seg_data = dict(list(y.groupby([])))\n",
    "\n",
    "#分割数据\n",
    "seg_data = dict(list(data.groupby(['yr'])))\n",
    "train_data = pd.DataFrame(seg_data[0])\n",
    "test_data = pd.DataFrame(seg_data[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     yr  holiday  workingday  weathersit      temp       hum  windspeed\n",
      "365   1        0           0           1  0.370000  0.692500   0.192167\n",
      "366   1        1           0           1  0.273043  0.381304   0.329665\n",
      "367   1        0           1           1  0.150000  0.441250   0.365671\n",
      "368   1        0           1           2  0.107500  0.414583   0.184700\n",
      "369   1        0           1           1  0.265833  0.524167   0.129987\n",
      "370   1        0           1           1  0.334167  0.542083   0.167908\n",
      "371   1        0           0           1  0.393333  0.531667   0.174758\n",
      "372   1        0           0           1  0.337500  0.465000   0.191542\n",
      "373   1        0           1           2  0.224167  0.701667   0.098900\n",
      "374   1        0           1           1  0.308696  0.646522   0.187552\n",
      "375   1        0           1           2  0.274167  0.847500   0.131221\n",
      "376   1        0           1           2  0.382500  0.802917   0.180967\n",
      "377   1        0           1           1  0.274167  0.507500   0.378108\n",
      "378   1        0           0           1  0.180000  0.457500   0.187183\n",
      "379   1        0           0           1  0.166667  0.419167   0.251258\n",
      "380   1        1           0           1  0.190000  0.522500   0.231358\n",
      "381   1        0           1           2  0.373043  0.716087   0.349130\n",
      "382   1        0           1           1  0.303333  0.443333   0.415429\n",
      "383   1        0           1           1  0.190000  0.497500   0.220158\n",
      "384   1        0           1           2  0.217500  0.450000   0.202750\n",
      "385   1        0           0           2  0.173333  0.831250   0.222642\n",
      "386   1        0           0           2  0.162500  0.796250   0.199638\n",
      "387   1        0           1           2  0.218333  0.911250   0.110708\n",
      "388   1        0           1           1  0.342500  0.835833   0.123767\n",
      "389   1        0           1           1  0.294167  0.643750   0.161071\n",
      "390   1        0           1           2  0.341667  0.769583   0.073396\n",
      "391   1        0           1           2  0.425000  0.741250   0.342667\n",
      "392   1        0           0           1  0.315833  0.543333   0.210829\n",
      "393   1        0           0           1  0.282500  0.311250   0.240050\n",
      "394   1        0           1           1  0.269167  0.400833   0.215792\n",
      "..   ..      ...         ...         ...       ...       ...        ...\n",
      "701   1        0           0           2  0.347500  0.823333   0.124379\n",
      "702   1        0           1           1  0.452500  0.767500   0.082721\n",
      "703   1        0           1           1  0.475833  0.733750   0.174129\n",
      "704   1        0           1           1  0.438333  0.485000   0.324021\n",
      "705   1        0           1           1  0.255833  0.508750   0.174754\n",
      "706   1        0           1           2  0.320833  0.764167   0.130600\n",
      "707   1        0           0           2  0.381667  0.911250   0.101379\n",
      "708   1        0           0           2  0.384167  0.905417   0.157975\n",
      "709   1        0           1           2  0.435833  0.925000   0.190308\n",
      "710   1        0           1           2  0.353333  0.596667   0.296037\n",
      "711   1        0           1           2  0.297500  0.538333   0.162937\n",
      "712   1        0           1           1  0.295833  0.485833   0.174129\n",
      "713   1        0           1           1  0.281667  0.642917   0.131229\n",
      "714   1        0           0           1  0.324167  0.650417   0.106350\n",
      "715   1        0           0           2  0.362500  0.838750   0.100742\n",
      "716   1        0           1           2  0.393333  0.907083   0.098258\n",
      "717   1        0           1           1  0.410833  0.666250   0.221404\n",
      "718   1        0           1           1  0.332500  0.625417   0.184092\n",
      "719   1        0           1           2  0.330000  0.667917   0.132463\n",
      "720   1        0           1           2  0.326667  0.556667   0.374383\n",
      "721   1        0           0           1  0.265833  0.441250   0.407346\n",
      "722   1        0           0           1  0.245833  0.515417   0.133083\n",
      "723   1        0           1           2  0.231304  0.791304   0.077230\n",
      "724   1        1           0           2  0.291304  0.734783   0.168726\n",
      "725   1        0           1           3  0.243333  0.823333   0.316546\n",
      "726   1        0           1           2  0.254167  0.652917   0.350133\n",
      "727   1        0           1           2  0.253333  0.590000   0.155471\n",
      "728   1        0           0           2  0.253333  0.752917   0.124383\n",
      "729   1        0           0           1  0.255833  0.483333   0.350754\n",
      "730   1        0           1           2  0.215833  0.577500   0.154846\n",
      "\n",
      "[366 rows x 7 columns]\n"
     ]
    }
   ],
   "source": [
    "#从分割数据中分离输入特征x和y\n",
    "Y_train = train_data['cnt'].values\n",
    "Y_test = test_data['cnt'].values\n",
    "\n",
    "X_train = train_data.drop('cnt',axis = 1)\n",
    "X_test = test_data.drop('cnt',axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandarScaler\n",
    "\n",
    "ss_x = StandardScaler()\n",
    "ss_y = StandardScaler()\n",
    "\n",
    "X_train = ss_X.fit_transform(X_train)\n",
    "X_test = ss_X.transform(X_te)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
